package Human;

use Moose;
use Moose::Util::TypeConstraints;

subtype 'Sex'
	=> as 'Str'
	=> where { $_ =~ m{^[mf]$}s };

has 'sex'	=> ( is => 'ro', isa => 'Sex', required => 1 );

has 'mother'	=> ( is => 'ro', isa => 'Human' );
has 'father'	=> ( is => 'ro', isa => 'Human' );

use overload '+' => \&_overload_add, fallback => 1;

sub _overload_add {
	my ( $one, $two ) = @_;
	
	die('Only male and female humans may create children')
		if ( $one->sex() eq $two->sex() );
	
	my ( $mother, $father ) = ( $one->sex eq 'f' ? ($one,$two) : ($two,$one) );
	my $sex = 'f';
	$sex = 'm' if ( rand() >=0.5 );
	
	return Human->new(
		sex	=> $sex,
		mother	=> $mother,
		father	=> $father,
	);
}

__PACKAGE__->meta->make_immutable;